<%--
  Created by IntelliJ IDEA.
  User: de'l'l
  Date: 2025/8/29
  Time: 18:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%-- workManager的 workorderAdd --%>
    <title>aaa图书借阅系统</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //1.账号失去焦点
            $("[name='userCode']").blur(function () {
                var val = $(this).val();
                if (val.length == 0) {
                    alert("用户名不能为空！");
                    return false;
                }
                return true;
            });

            //2.密码失去焦点
            $("[name='pwd']").blur(function () {
                var val = $(this).val();
                if (val.length == 0) {
                    alert("密码不能为空！");
                    return false;
                }
                return true;
            });

            //表单验证
            function ck(val) {
                let reg = /^[^'|&]{4,6}$/;
                if (reg.test(val)) {
                    return true;
                } else {
                    alert("输入格式有误，请重新输入！")
                    return false;
                }
            }

            //3.点击 登录按钮 发送 异步请求
            $("[value='登录']").click(function () {
                var userCode = $("[name='userCode']").val();
                var pwd = $("[name='pwd']").val();
                if (ck(userCode) && ck(pwd)) {

                    $.get("user/finduser",
                        {
                            "userCode": userCode,
                            "pwd": pwd
                        },
                        function (boo) {
                            JSON.stringify(boo);
                            if (boo) {
                                //账号密码正确
                                window.location.href = "bookList.jsp";
                            } else {
                                alert("登录失败，用户名或密码有误！");
                            }
                        }
                    );
                }
            });

        });


    </script>
</head>
<body>
<table>
    <caption>aaa图书借阅系统</caption>
    <tr>
        <td> 登录账号：</td>
        <td>
            <input type="text" name="userCode">
        </td>
    </tr>
    <tr>
        <td> 登录密码：</td>
        <td>
            <input type="password" name="pwd">
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="登录">
            <input type="button" value="注册">
        </td>
    </tr>
</table>


</body>
</html>
